	<?php
	class MySession {
		public $session;
		public function __construct() {
			@ini_set ( 'session.name', 'sid' );
			@ini_set ( 'session.use_trans_sid', 0 );
			@ini_set ( 'session.gc_maxlifetime', 3600 );
			@ini_set ( 'session.use_cookies', 1 );
			@ini_set ( 'session.cookie_path', '/' );
			@ini_set ( 'session.cookie_domain', '189play.com' );
			@session_module_name ( 'user' );
			session_set_save_handler ( array (
				
				$this, 
				'open' 
			), array (
				
				$this, 
				'close' 
			), array (
				
				$this, 
				'read' 
			), array (
				
				$this, 
				'write' 
			), array (
				
				$this, 
				'destroy' 
			), array (
				
				$this, 
				'gc' 
			) );
			$this->session = new Session ( );
		}
		public function open($save_path, $session_name) {
			return true;
		}
		public function close() {
			$this->session = '';
			return TRUE;
		}
		public function read($sessid) {
			$ret = $this->session->findByPk ( $sessid );
			if (! isset ( $sessid )) {
				return FALSE;
			}
			if ($ret->session_last_access > time ()) {
				return $ret->session_data;
			}
			return FALSE;
		}
		public function write($sessid, $data) {
			if(empty($data)){
				return FALSE;
			}
			$ret = $this->session->findByPk ( $sessid );
			if (empty ( $ret )) {
				$this->session->sessid = $sessid;
				$this->session->session_last_access = time () + 100000;
				$this->session->session_data = $data;
				$this->session->inputtime = time ();
				$this->session->save ();
				return TRUE;
			} else {
				if ($ret->session_last_access > time ()) {
					$this->session->updateByPk ( $ret->sessid, array (
						
						'session_last_access' => time () + 100000, 
						'inputtime' => time () 
					) );
					return TRUE;
				}
				return FALSE;
			}
		}
		public function destroy($sessid) {
			$this->session->deleteByPk ( $sessid );
		}
		public function gc($maxlifetime) {
			$this->session->deleteAll ( array (
				
				'condition' => 'session_last_access<unix_timestamp()' 
			) );
		}
	}
	?>